package me.send.business.service.service;

import java.util.HashMap;
import java.util.Map;

import me.send.business.base.ErrorEntity;
import me.send.business.base.SendVariable;
import me.send.business.service.BaseService;
import me.send.business.service.mapper.PhonenumberMapper;
import me.send.business.service.pojo.Phonenumber;
import me.send.framework.util.Base64Util;
import me.send.framework.util.HelperUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PhonenumberService extends BaseService{

	@Autowired
	private PhonenumberMapper phonenumberMapper;
	
	// 获取不到 phonenumber  2015年6月5日10:50:51 
	public Map<String, Object> system_save(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(SendVariable.COMM_ERROR, error_1000());
		// 生成验证码 
		String code = Base64Util.getBase64(System.currentTimeMillis() + SendVariable.phonenumber_password);
		// 生成一个对象 2015年6月5日10:59:27
		Phonenumber phonenumber = new Phonenumber();
		phonenumber.setCreatetime(HelperUtil.getCurrentDate());
		phonenumber.setDevicenumber(code);
		phonenumberMapper.system_save(phonenumber);
		map.put(SendVariable.COMM_CODE, code);
		return map;
	}
	
	// 调用保存的方法 2015年6月1日15:51:33
	public ErrorEntity save(String devicenumber){
		if (isDevicenumber(devicenumber)) {
			Phonenumber phonenumber = new Phonenumber();
			// 设置对象下面的值
			phonenumber.setCreatetime(HelperUtil.getCurrentDate());
			phonenumber.setDevicenumber(devicenumber);
			// 最后保存下面的对象
			phonenumberMapper.save(phonenumber);
			return error_1000();
		}
		return error_1002();
	}
	
}
